#include "titletext.h"

titleText::titleText(AudioPlayerBackend * music, QColor color, int fontSize)
{
    this->music = music;

//#ifdef Q_WS_QWS
    //QFont font(QString("DejaVuSans"),100,QFont::Bold,false);
//#else
    QFont font(QString("DejaVuSans"),fontSize,QFont::Bold,false);
//#endif
    this->setDefaultTextColor(color);
    this->setFont(font);
    this->setTextWidth(800);
    QFontInfo finfo(font);
    //qDebug() << finfo.family() << " - " << finfo.pointSize() << " - " << finfo.weight();
}

void titleText::updateCurrentTitle()
{

    if(music->isPlaying() || music->isPaused()){
            this->setArtist(music->getCurrentSongArtist());
            this->setAlbum(music->getCurrentSongAlbum());
            this->setTitle(music->getCurrentSongTitle());
            this->reload();
    }else{
            this->reset();
    }

    this->setX((this->scene()->width() - this->boundingRect().width()) / 2);
}

void titleText::mousePressEvent ( QGraphicsSceneMouseEvent * event )
{
        emit titleClicked();
        qDebug() << "Event => stopPressed()";
}

void titleText::setArtist(QString artist)
{
    this->artist = artist;
}

QString titleText::getArtist()
{
    return artist;
}

void titleText::setAlbum(QString album)
{
    this->album = album;
}

QString titleText::getAlbum()
{
    return album;
}

void titleText::setTitle(QString title)
{
    this->title = title;
}

QString titleText::getTitle()
{
    return title;
}

void titleText::reload()
{
    this->setHtml(QString("<center>" + this->artist.toUpper() + " (" + this->album + ") <br/> " + this->title + "</center>"));
    this->textChanged();

}

void titleText::reset()
{
    /*
    this->album = "";
    this->artist = "";
    this->title = "";
    this->setPlainText("");
    this->textChanged();
    */
}

